#HTML <a>
The <a> HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address.
#Attributes
-
attributionsrc
Experimental : Specifies that you want the browser to send anAttribution-Reporting-Eligible
header. On the server-side this is used to trigger sending anAttribution-Reporting-Register-Source
header in the response, to register a navigation-based attribution source.The browser stores the source data associated with the navigation-based attribution source (as provided in the
Attribution-Reporting-Register-Source
response header) when the user clicks the link. See the Attribution Reporting API for more details.There are two versions of this attribute that you can set:
-
Boolean, i.e., just the
attributionsrc
name. This specifies that you want theAttribution-Reporting-Eligible
header sent to the same server as thehref
attribute points to. This is fine when you are handling the attribution source registration on the same server. -
Value containing one or more URLs, for example:
html
attributionsrc="https://a.example/register-source https://b.example/register-source"
This is useful in cases where the requested resource is not on a server you control, or you just want to handle registering the attribution source on a different server. In this case, you can specify one or more URLs as the value of
attributionsrc
. When the resource request occurs, theAttribution-Reporting-Eligible
header will be sent to the URL(s) specified inattributionsrc
in addition to the resource origin. These URLs can then respond with theAttribution-Reporting-Register-Source
to complete registration.Note: Specifying multiple URLs means that multiple attribution sources can be registered on the same feature. You might for example have different campaigns that you are trying to measure the success of, which involve generating different reports on different data.
<a>
elements cannot be used as attribution triggers, only sources. -
-
download
: Causes the browser to treat the linked URL as a download. Can be used with or without afilename
value:-
Without a value, the browser will suggest a filename/extension, generated from various sources:
- The
Content-Disposition
HTTP header - The final segment in the URL path
- The media type (from the
Content-Type
header, the start of adata:
URL, orBlob.type
for ablob:
URL)
- The
-
filename
: defining a value suggests it as the filename./
and\
characters are converted to underscores (_
). Filesystems may forbid other characters in filenames, so browsers will adjust the suggested name if necessary.
Note:
-
download
only works for same-origin URLs, or theblob:
anddata:
schemes. -
How browsers treat downloads varies by browser, user settings, and other factors. The user may be prompted before a download starts, or the file may be saved automatically, or it may open automatically, either in an external application or in the browser itself.
-
If the
Content-Disposition
header has different information from thedownload
attribute, resulting behavior may differ:- If the header specifies a
filename
, it takes priority over a filename specified in thedownload
attribute. - If the header specifies a disposition of
inline
, Chrome and Firefox prioritize the attribute and treat it as a download. Old Firefox versions (before 82) prioritize the header and will display the content inline.
- If the header specifies a
-
-
href
: The URL that the hyperlink points to. Links are not restricted to HTTP-based URLs — they can use any URL scheme supported by browsers:- Telephone numbers with
tel:
URLs - Email addresses with
mailto:
URLs - SMS text messages with
sms:
URLs - Executable code with
javascript:
URLs - While web browsers may not support other URL schemes, websites can with
registerProtocolHandler()
Moreover other URL features can locate specific parts of the resource, including:
- Sections of a page with document fragments
- Specific text portions with text fragments
- Pieces of media files with media fragments
- Telephone numbers with
-
hreflang
: Hints at the human language of the linked URL. No built-in functionality. Allowed values are the same as the globallang
attribute. -
ping
: A space-separated list of URLs. When the link is followed, the browser will sendPOST
requests with the bodyPING
to the URLs. Typically for tracking. -
referrerpolicy
: How much of the referrer to send when following the link.no-referrer
: TheReferer
header will not be sent.no-referrer-when-downgrade
: TheReferer
header will not be sent to origins without TLS (HTTPS).origin
: The sent referrer will be limited to the origin of the referring page: its scheme, host, and port.origin-when-cross-origin
: The referrer sent to other origins will be limited to the scheme, the host, and the port. Navigations on the same origin will still include the path.same-origin
: A referrer will be sent for same origin, but cross-origin requests will contain no referrer information.strict-origin
: Only send the origin of the document as the referrer when the protocol security level stays the same (HTTPS→HTTPS), but don't send it to a less secure destination (HTTPS→HTTP).strict-origin-when-cross-origin
(default): Send a full URL when performing a same-origin request, only send the origin when the protocol security level stays the same (HTTPS→HTTPS), and send no header to a less secure destination (HTTPS→HTTP).unsafe-url
: The referrer will include the origin and the path (but not the fragment, password, or username). This value is unsafe, because it leaks origins and paths from TLS-protected resources to insecure origins.
-
rel
: The relationship of the linked URL as space-separated link types. -
target
: Where to display the linked URL, as the name for a browsing context (a tab, window, or<iframe>
). The following keywords have special meanings for where to load the URL:_self
: The current browsing context. (Default)_blank
: Usually a new tab, but users can configure browsers to open a new window instead._parent
: The parent browsing context of the current one. If no parent, behaves as_self
._top
: The topmost browsing context. To be specific, this means the "highest" context that's an ancestor of the current one. If no ancestors, behaves as_self
._unfencedTop
: Allows embedded fenced frames to navigate the top-level frame (i.e., traversing beyond the root of the fenced frame, unlike other reserved destinations). Note that the navigation will still succeed if this is used outside of a fenced frame context, but it will not act like a reserved keyword.
Note: Setting
target="_blank"
on<a>
elements implicitly provides the samerel
behavior as settingrel="noopener"
which does not setwindow.opener
. -
type
: Hints at the linked URL's format with a MIME type. No built-in functionality.